package org.NooLab.itexx.retrieval;

import java.util.ArrayList;

import org.NooLab.itexx.ITexxWindowIntf;
import org.NooLab.utilities.strings.StringsUtil;




public class RequestUrlManager {

	ITexxWindowIntf mainApp ; 
	RetrievalEngine retrievalEngine ;
	// ========================================================================
	public RequestUrlManager( ITexxWindowIntf app, 
							  RetrievalEngine rEngine) {
		//
		mainApp = app;
		retrievalEngine = rEngine;
	}
	// ========================================================================
	public String prepareSearchEngineUrl(String searchStr, String engine, int startindex) {
		
		// ArrayList<String> rqStrs= new ArrayList<String>();
		String rqStr="";
		
		if (engine.toLowerCase().contains("google")){
			// we have multiples of 10 by default
			rqStr = prepareGoogleRequestString(searchStr,startindex);
		}

		// http://www.bing.com/search?q=putnam+progam&go=&qs=ds&form=QBLH&filt=all
		
		// http://www.bing.com/search?q=putnam+progam&go=&qs=ds&filt=all&first=81
		
		
		return rqStr;
	}


	/**
	 * prepares a basic request string -> put it to an object !!! (because there are lots of options
	 * @param searchstr
	 * @return
	 */
	private String prepareGoogleRequestString(String searchstr, int startIndex) {
		// 
		String rqStr = ""; // read the template from config file
		
		searchstr = searchstr.trim();
		searchstr = StringsUtil.replaceall(searchstr, "  ", " ");
		searchstr = StringsUtil.replaceall(searchstr, " ", "+");
		searchstr = StringsUtil.replaceall(searchstr, " ", "");
		
		String startIndicator="";
		if (startIndex>1){
			startIndicator="&start="+startIndex;
		}
		
		rqStr = "http://www.google.com/search?num=100&hl=de&newwindow=0"+startIndicator+"&sa=N&q="+searchstr ;// processing+p5&oq=processing+p5
		
		return rqStr;
	}

	
	
}
